const { dbUri } = require('../config/config.deafult')
/**
 * 连接mongodb数据库
 */
const mongoose = require('mongoose');
mongoose.connect(dbUri, {

});

// 获取连接
const db = mongoose.connection
db.on('error', err => {
  console.log(`MongoDB数据库连接失败`, err)
})

db.on('open', () => {
  console.log('MongoDB数据库连接成功')
})

// 组织导出用户模型
module.exports = {
  User: mongoose.model('User', require('./user')),
  Article: mongoose.model('Article', require('./article'))
}

// const Cat = mongoose.model('Cat', { name: String });

// const kitty = new Cat({ name: '加菲猫-虎比' });
// kitty.save().then(() => console.log('meow'));